package com.itheima01;

/**
 * @author Xiao
 * @date 2021/7/10
 */
public class AnimalDemo {
    public static void main(String[] args) {
        Animal a = new Cat();     //向上转型：父类引用a接收子类对象new Cat()
        a.eat();
//        a.play();       //报错：play()属于子类特有功能，父类引用变量a无法访问

        Cat c = (Cat) a;   //向下转型：将父类引用a强转为子类引用c
        c.eat();
        c.play();

        a = new Dog();
        a.eat();
        Cat cc = (Cat) a;
        cc.eat();   //  ClassCastException类型转换异常
    }
}
